<template>

	<div class="user">
		<!--搜索表单-->
		<div class="common-seach-wrap">
			<el-form size="small" :inline="true" :model="formInline" class="demo-form-inline">
				<el-form-item label="用户信息">
					<el-input v-model="formInline.search" placeholder="请输入昵称|手机号"></el-input>
				</el-form-item>
				<el-form-item label="奖品信息">
					<el-input v-model="formInline.record_name" placeholder="请输入奖品名称"></el-input>
				</el-form-item>
				<el-form-item label="奖励类型">
					<el-select size="small" v-model="formInline.type" placeholder="请选择">
						<el-option label="全部" :value="-1"></el-option>
						<el-option v-for="(item, index) in lotteryType" :key="index" :label="item"
							:value="index"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="状态">
					<el-select size="small" v-model="formInline.status" placeholder="请选择">
						<el-option label="全部" :value="-1"></el-option>
						<el-option label="已兑换" :value="1"></el-option>
						<el-option label="未兑换" :value="0"></el-option>
					</el-select>
				</el-form-item>
				<el-form-item label="时间">
					<div class="block">
						<span class="demonstration"></span>
						<el-date-picker v-model="formInline.reg_date" type="daterange" value-format="YYYY-MM-DD"
							range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期"></el-date-picker>
					</div>
				</el-form-item>
				<el-form-item>
					<el-button type="primary" icon="Search" @click="onSubmit">查询</el-button>
				</el-form-item>
				<el-form-item>
					<el-button size="small" type="success" @click="onExport"
						v-auth="'/plus/lottery/export'">导出</el-button>
				</el-form-item>
			</el-form>
		</div>
		<!--内容-->
		<div class="product-content">
			<div class="table-wrap">
				<el-table size="small" :data="tableData" border style="width: 100%" v-loading="loading">
					<el-table-column prop="record_id" label="ID" width="80"></el-table-column>
					<el-table-column prop="user_id" label="用户ID" width="80"></el-table-column>
					<el-table-column prop="nickName" label="昵称"></el-table-column>
					<el-table-column prop="avatarUrl" label="头像">
						<template #default="scope">
							<img v-if="scope.row.avatarUrl" :src="scope.row.avatarUrl" :width="30" :height="30" />
						</template>
					</el-table-column>
					<el-table-column prop="mobile" label="手机号"></el-table-column>
					<el-table-column prop="record_name" label="中奖内容"></el-table-column>
					<el-table-column prop="lottery_type_text" label="中奖类型"></el-table-column>
					<el-table-column prop="status" label="状态">
						<template #default="scope">
							<span v-if="scope.row.status==1">已兑换</span>
							<span class="red" v-if="scope.row.status==0">未兑换</span>
						</template>
					</el-table-column>
					<el-table-column prop="create_time" label="抽奖时间" width="140"></el-table-column>
					<el-table-column prop="remark" label="备注" width="140"></el-table-column>
					<el-table-column fixed="right" label="操作" width="80">
						<template #default="scope">
							<el-button v-if="scope.row.express_id > 0" @click="getLogistics(scope.row)" link
								type="primary" size="small" v-auth="'/plus/lottery/express'">查看物流
							</el-button>
							<el-button @click="remarks(scope.row)" v-auth="'/plus/lottery/remark'" link type="primary" size="small">备注
							</el-button>
							<el-button @click="sendClick(scope.row)" link type="primary" v-auth="'/plus/lottery/send'"
								size="small" v-if="
							                  scope.row.status == 1 &&
							                  scope.row.prize_type == 3 &&
							                  scope.row.delivery_status == 10
							                ">发放</el-button>
							<el-button @click="detailClick(scope.row)" link type="primary"
								v-auth="'/plus/lottery/detail'" size="small" v-if="
							                  scope.row.status == 1 &&
							                  scope.row.prize_type == 3 &&
							                  scope.row.delivery_status == 20
							                ">详情</el-button>
						</template>
					</el-table-column>
				</el-table>
			</div>
			<!--分页-->
			<div class="pagination">
				<el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" background
					:current-page="curPage" :page-size="pageSize" layout="total, prev, pager, next, jumper"
					:total="totalDataNumber"></el-pagination>
			</div>
		</div>
		<Logistics v-if="isLogistics" :logisticsData="logisticsData" :isLogistics="isLogistics"
			@closeDialog="closeLogistics"></Logistics>
		<remarks v-if="is_remark" :is_remark="is_remark" :Val="remarkVal"
			@closeDialog="closeDialogFunc($event, 'remark')"></remarks>
		<!--处理-->
		<Send v-if="open_send" :open_send="open_send" :model="currentModel" :expressList="expressList"
			@closeDialog="closeDialogFunc($event, 'send')"></Send>
		<!--处理-->
		<Detail v-if="open_detail" :open_detail="open_detail" :model="currentModel"
			@closeDialog="closeDialogFunc($event, 'detail')"></Detail>
	</div>
</template>

<script>
	import {
		recordList,
		express
	} from '@/api/lottery.js';
	import remarks from "./dialog/remarks.vue";
	import Logistics from "@/components/logistics/viewLogistics.vue";
	import Send from "./dialog/Send.vue";
	import Detail from "./dialog/Detail.vue";
	import qs from 'qs';
	import {
		useUserStore
	} from '@/store';
	const {
		token
	} = useUserStore();
	export default {
		components: {
			remarks,
			Logistics,
			Detail,
			Send
		},
		data() {
			return {
				/*是否加载完成*/
				loading: true,
				/*列表数据*/
				tableData: [],
				/*一页多少条*/
				pageSize: 20,
				/*一共多少条数据*/
				totalDataNumber: 0,
				/*当前是第几页*/
				curPage: 1,
				/*横向表单数据模型*/
				formInline: {
					search: '',
					reg_date: '',
					status: '',
					record_name: '',
					type: -1,
					token,
				},
				logisticsData: {},
				isLogistics: false,
				is_remark: false,
				remarkVal: {},
				lotteryType: [],
				open_send: false,
				open_detail: false,
				currentModel: {},
				expressList: [],
			};
		},
		created() {
			/*获取列表*/
			this.getTableList();
		},
		methods: {
			sendClick(e) {
				this.open_send = true;
				this.currentModel = e;
			},
			detailClick(e) {
				this.open_detail = true;
				this.currentModel = e;
			},
			/*关闭弹窗*/
			closeDialogFunc(e, f) {
				if (f == "send") {
					this.open_send = e.openDialog;
					if (e.type == "success") {
						this.getTableList();
					}
				}
				if (f == "detail") {
					this.open_detail = e.openDialog;
					if (e.type == "success") {
						this.getTableList();
					}
				}
				if (f == "remark") {
					this.is_remark = e.openDialog;
					if (e.type == "success") {
						this.getTableList();
					}
				}
			},
			openLogistics() {
				this.isLogistics = true;

			},
			closeLogistics() {
				this.isLogistics = false;
			},
			remarks(e) {
				this.remarkVal = e;
				this.is_remark = true;
			},
			getLogistics(row) {
				let self = this;
				let Params = {
					record_id: row.record_id,
					express_id: row.express_id,
					express_no: row.express_no,
				};
				self.loading = true;
				express(Params, true)
					.then((res) => {
						self.loading = false;
						self.logisticsData = res.data.express.list;
						self.openLogistics();
					})
					.catch((error) => {
						self.loading = false;
					});
			},

			/*选择第几页*/
			handleCurrentChange(val) {
				let self = this;
				self.curPage = val;
				self.loading = true;
				self.getTableList();
			},

			/*每页多少条*/
			handleSizeChange(val) {
				this.curPage = 1;
				this.pageSize = val;
				this.getTableList();
			},
			/*获取列表*/
			getTableList() {
				let self = this;
				let Params = self.formInline;
				Params.page = self.curPage;
				Params.list_rows = self.pageSize;
				recordList(Params, true)
					.then(res => {
						self.loading = false;
						self.tableData = res.data.list.data;
						self.lotteryType = res.data.lotteryType;
						self.totalDataNumber = res.data.list.total;
						self.expressList = res.data.expressList;
					})
					.catch(error => {
						self.loading = false;
					});
			},
			/*搜索查询*/
			onSubmit() {
				let self = this;
				self.loading = true;
				self.curPage = 1;
				self.getTableList();
			},
			onExport: function() {
				let url = "/index.php/shop/plus.lottery/export";
				let params = this.formInline;
				this.$filter.onExportFunc(url, params);
			},
		}
	};
</script>
<style lang="scss" scoped></style>